<?php 
$model = new Administrator_Model_Component();
$siteinfo = $model->GetSiteInfo();
$title = 'Danh sách View';
$button = '<button class="add button" name="btadd" value="btadd" type="submit"></button>';
switch ($this->task) {
	case 'new':
	$title = 'Thêm View';
	$button = '<button class="save button" name="btsave" value="btsave" type="submit"></button>';
	$button .= '<button class="back button" name="btback" value="btback" type="submit"></button>';
	$button .= '<button class="option button" name="btoption" value="btoption" type="submit"></button>';
	break;
	case 'edit':
	$title = 'Sửa View';
	$button = '<button class="save button" name="btsave" value="btsave" type="submit"></button>';
	$button .= '<button class="back button" name="btback" value="btback" type="submit"></button>';
	$button .= '<button class="option button" name="btoption" value="btoption" type="submit"></button>';
	break;
	case 'list':
	$title = 'Danh sách View';
	$button = '<button class="add button" name="btadd" value="btadd" type="submit"></button>';
	$button .= '<button class="edit button" name="btedit" value="btedit" type="submit"></button>';
	$button .= '<button class="delete button" name="btdelete" value="btdelete" type="submit"></button>';
	$button .= '<button class="able button" name="btable" value="btable" type="submit"></button>';
	$button .= '<button class="check button" name="btcheck" value="btcheck" type="submit"></button>';
	$button .= '<button class="option button" name="btoption" value="btoption" type="submit"></button>';
	break;
	default:
		;
	break;
}
?>
<form method="post" enctype="multipart/form-data">
<div class="nav">
	<div class="navbutton">
		<?php echo $button;?>
	</div>
</div>
<div class="sheet">
	<div class="mana-title"><?php echo $title?></div>
	<div class="intro">
		<div class="form">
<?php 
	if($this->task != 'list'){
		$name = '';
		$display = '';
		$action = '';
		if($this->task == 'edit'){
			$info = $model->GetViewInfo($this->id); 
			$name = $info['name'];
			$display = $info['display'];
			$action = $info['action'];
		}
		echo '<div class="small edit">';
			echo '<div class="element">';
				echo '<div class="eleft">Tên View : </div>';
				echo '<div class="eright"><input type="text" name="name" value="'.$name.'"></div>';
			echo '</div>';			
			echo '<div class="element">';
				echo '<div class="eleft">Hiển thị : </div>';
				echo '<div class="eright"><input type="text" name="display" value="'.$display.'"></div>';
			echo '</div>';
			echo '<div class="element">';
			echo '<div class="eleft">Addon : </div>';
			echo '<div class="eright"> <select name="addon">';	
			foreach ($model->GetAllAction() as $value) {
				$selected = '';if($action == $value['id'])$selected = ' selected ="selected" ';
				echo '<option '.$selected.' value="'.$value['id'].'">'.$value['display'].'</option>';
			}
			
			echo '</select></div>';
			echo '</div>';
		echo '</div>';//end small
	}
	else {
echo '<table class="list-item">';
	echo '<thead>';
		echo '<th class="stt">STT</th>';
		echo '<th class="checkbox"><input id="selectall" type="checkbox" ></th>';
		echo '<th class="">Tên View</th>';
		echo '<th class="">Hiển thị</th>';
		echo '<th class="">Addon</th>';
		echo '<th class="action">Action</th>';
		echo '<th class="id">ID</th>';
	echo '</thead>';
	echo '<tbody>';
	$i=1;
	foreach ($model->GetAllView() as $value) {
		$class="";if($i%2==0)$class = 'focus';
		echo '<tr class="'.$class.'">';
			echo '<td class="stt">'.$i.'</td>';
			echo '<td class="checkbox"><input id="'.$value['id'].'" type="checkbox" name="'.$value['id'].'" ></td>';
			echo '<td class="">'.$value['name'].'</td>';
			echo '<td class="">'.$value['display'].'</td>';
			$cinfo = $model->GetActionInfo($value['action']);
			echo '<td class="">'.$cinfo['display'].'</td>';
			echo '<td class="action"><a href="'.BASE_URL.'/administrator/component/view?task=edit&id='.$value['id'].'"><img src="'.$this->dirImg.'/edit.png"></a><a href="#" onclick="DeleteSection()"><img src="'.$this->dirImg.'/delete.png"></a></td>';
			echo '<td class="id">'.$value['id'].'</td>';
			echo '</tr>';
		$i++;
	}
	echo '</tbody>';
	echo '<tfoot>';
	echo '</tfoot>';
echo '</table>';
}
?>		
		</div>
	</div>
</div>
</form>